home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / LISTINGS / V_13_04 / CHAPMAN2 / CHAPMAN2.ZIP / TSTASSRT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-19  |  927 b   |  33 lines

  1. /* tstassrt.cpp - test program for assertions */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <ctype.h>
  6. #include <string.h>
  7. #include "errmgr.hpp"                   /* ASSERT() */
  8.  
  9.  
  10. int main(int argc,char *argv[])
  11. {
  12.     /* this program should be run three times - once with assertions off, */
  13.     /* once to get past the assertions (allow execution to continue), and */
  14.     /* once to fail them. */
  15.  
  16.     char *s = "hello!";
  17.     char buf[80];
  18.  
  19.     /* turn assertions off if the user so desires. */
  20.  
  21.     printf("Turn assertions off [no]? ");
  22.     fgets(buf,sizeof(buf),stdin);
  23.     err_mgr.set_assert_flag(toupper(*buf) != 'Y');
  24.  
  25.     ASSERT(strcmp("hello",s));          /* string constants in assertions? */
  26.     ASSERT(!strcmp("hello",s));
  27.     ASSERT(1 == 2);                     /* had better fail! */
  28.     fputs("got past assertion\n",stderr);
  29.     return EXIT_SUCCESS;
  30.  
  31. }  /* end of main() */
  32.  
  33.